習慣上的寫法


Posted by mijouhsieh on 2023-05-01

outline:
Promise 物件實例中,

1 Promise 物件實例中,例子裡沒有設計 reject - catch 的段落,因此參數寫 _reject

在習慣上,加底線表示後面沒有用到這個參數。

 new Promise((resolve, _reject) => {
    for (const [user_index, user] of users.entries()) {
      // 創建使用者資料(user): model.create
      UserModel.create({
        ...user
      }).then((user) => {
        // 對每個user建立相對應餐廳資料
        return RestaurantModel.create(restaurants)
      }).then(() => {
        resolve()
      }).catch(error => {
        console.log(error)
      })
    }
  }).then(() => {
    // 等待所有使用者的餐廳資料創建完成
    console.log('所有使用者與餐廳資料創建完成')
    process.exit()
  })

#習慣上的寫法







Related Posts

[css] 給點顏色瞧瞧 - hex, rgb, hsl

[css] 給點顏色瞧瞧 - hex, rgb, hsl

學 JavaScript 的那些筆記

學 JavaScript 的那些筆記

[JS Behind The Scene] 從簡單例子了解 hoisting 的運作機制

[JS Behind The Scene] 從簡單例子了解 hoisting 的運作機制


Comments